package org.ume.school.modules;

import com.bluesimon.wbf.*;
import com.bluesimon.wbf.view.AbstractPageDataTunnel;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Django on 2017/7/16.
 */
@Component
public class PageDataTunnel extends AbstractPageDataTunnel implements InitializingBean {
    private static final String API_SERVER = "http://localhost:8080";

    static {
        List<String> apis = new ArrayList<>();
        // 从外部传入offset ，limit ; 如果没有传入值，则默认为1 与 20.
        apis.add("/v0.1/article/all?offset={offset=1}&limit={limit=20}&orderby={orderby=createTime}&direction={direction=desc}");
        apis.add("/v0.1/article/all?offset={offset=1}&limit={limit=10}&orderby={orderby=greats}&direction={direction=desc}");
        moduleToApis.put("articles", apis);

        //
        apis = new ArrayList<>();
        apis.add("/v0.1/article/{id}");
        moduleToApis.put("article", apis);

        apis = new ArrayList<>();
        apis.add("/v0.1/article/excellents");
        moduleToApis.put("home", apis);

        //
//        apis = new ArrayList<>();
//        apis.add("/v0.1/user/vaild_login");
//        moduleToApis.put("indite",apis);

    }

    @Override
    public String proDoGet(String m, String api, Principle principle) {
        api = API_SERVER + api;
        return api;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("=============================PageDataTunnel");
    }
}
